package com.medication.config;

import java.util.Map;

import javax.servlet.ServletContext;

/**
 * web容器上下文
 */
public class ServletContextHolder {

	// 系统配置
	public static final String APP_CONFIG_KEY = "appConfig";

	public static final String CONTEXT_PATH_KEY = "ctx";

	public static final String RESOURCE_PATH_KEY = "resourcePath";

	/** web容器 */
	private static ServletContext servletContext;

	/**
	 * 获取WEB应用上下文
	 */
	public static ServletContext getServletContext() {
		return servletContext;
	}

	/**
	 * 设置WEB应用上下文
	 */
	public static void setServletContext(ServletContext servletContext) {
		ServletContextHolder.servletContext = servletContext;
	}

	@SuppressWarnings("unchecked")
	public static Map<String, String> getAppConfigAttr() {
		return (Map<String, String>) servletContext.getAttribute(APP_CONFIG_KEY);
	}

	public static String getContextPathAttr() {
		return (String) servletContext.getAttribute(CONTEXT_PATH_KEY);
	}

	public static String getResourcePathAttr() {
		return (String) servletContext.getAttribute(RESOURCE_PATH_KEY);
	}

	public static Object getAttribute(String name) {
		return servletContext.getAttribute(name);
	}

}
